def divide_by2(n: int) -> str:
    """十进制转二进制"""
    from pythonds.basic import Stack

    str_stack = Stack()

    while n > 0:
        rem = n % 2
        str_stack.push(rem)
        n = n // 2

    bin_str = ""
    while not str_stack.empty():
        bin_str = bin_str + str(str_stack.pop())

    return bin_str


def base_converter(n: int, b: int) -> str:
    """十进制转2,8,16进制"""
    from pythonds.basic import Stack

    str_stack = Stack()
    digits = "0123456789ABCDEF"

    while n > 0:
        rem = n % b
        str_stack.push(digits[rem])
        n = n // b

    to_str = []
    while not str_stack.empty():
        to_str.append(str_stack.pop())

    return "".join(to_str)
